<template>
	<view class="bill-content">
		<view class="bill-header">
			<view class="bill-header-tips">支付金额</view>
			<view class="bill-header-money">￥{{order.price}}</view>
		</view>
		<!-- view class="bill-line">
			<view class="bill-line_param">订单号</view>
			<view class="bill-line_value">AOBEITINENG00123456789012345</view>
		</view> -->
		<view class="bill-tips">
			温馨提示：{{tips}}
			<!-- 锁住的视频需要付费，付费一个视频就可以在一年内任意观看和学习
			<text>小学一年级</text>全部体能视频。 -->
		</view>
		<view class="bill-methods">
			<view class="bill-methods_tips">支付方式</view>
			<radio-group @change="radioChange">
				<label class="uni-list-cell uni-list-cell-pd bill-methods_radio">
					<image src="../../static/imgs/payment/wxpay.png"></image>
					<view>
						<radio value="1" color="#FF6E00" :checked="payment == '1'" style="transform:scale(0.7)" />
					</view>
				</label>
				<label class="uni-list-cell uni-list-cell-pd bill-methods_radio padding">
					<image src="../../static/imgs/payment/zfbpay.png"></image>
					<view>
						<radio value="2" color="#FF6E00" :checked="payment == '2'" style="transform:scale(0.7)" />
					</view>
				</label>
			</radio-group>
		</view>
		<view class="button" @click="payClick">立即支付</view>
	</view>
</template>

<script>
	import {
		getSportPay
	} from "../../static/js/api/games.js";
	export default {
		data() {
			return {
				order: {},
				payment: '1',
				tips: '纸质证书费用+邮费=支付金额',
			}
		},
		onLoad(option) {
			if (option.order) {
				this.order = JSON.parse(option.order)
				console.log(this.order)
				if (this.order.orderType == 'cert') {
					this.tips = '纸质证书费用+邮费=支付金额'
				} else {
					this.tips = '锁住的视频需要付费，付费一个视频就可以在一年内任意观看和学习小学一年级全部体能视频。'
				}
			}
			// uni.dialog.dialogConfirm('仅需128元/年，小学一年级全部体能课程，任您观看学习。', () => {
			// 	//确定按钮
			// }, () => {
			// 	//取消按钮
			// }, '去支付', '下次再说', 'warning', '解锁小学一年级全部课程');
		},
		methods: {
			radioChange(e) {
				this.payment = e.detail.value
				console.log(50, e.detail.value)
			},
			payClick() {
				let _this = this
				
				if (_this.payment == '1') {
					getSportPay({
						"sport_id": _this.order.sport_id,
						"sport_user_id": _this.order.user_id,
						"pay_type": 1,
						"name": _this.order.name,
						"phone": _this.order.phone,
						"address": _this.order.address
					}).then(payRes => {
						console.log(75, payRes)
						uni.requestPayment({
							"provider": "wxpay",
							"orderInfo": {
								"appid": payRes.body.appid, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
								"noncestr": payRes.body.noncestr, // 随机字符串
								"package": payRes.body.package, // 固定值
								"partnerid": payRes.body.partnerid, // 微信支付商户号
								"prepayid": payRes.body.prepay_id, // 统一下单订单号 
								"timestamp": payRes.body.timestamp, // 时间戳（单位：秒）
								"sign": payRes.body.sign // 签名，这里用的 MD5/RSA 签名
							},
							success(sres) {
								console.log(sres)
								
								uni.navigateTo({
									url: "/pages/payment/success?orderid=" + payRes.order_id
								})
							},
							fail(e) {
								console.log(e)
								uni.showModal({
									content: "支付失败",
									showCancel: false
								})
							}
						})
					})

				} else {
					getSportPay({
						"sport_id": _this.order.sport_id,
						"sport_user_id": _this.order.user_id,
						"pay_type": 2,
						"name": _this.order.name,
						"phone": _this.order.phone,
						"address": _this.order.address
					}).then(payRes => {
						console.log(119,payRes)
						// payRes为String类型
						uni.requestPayment({
							provider: 'alipay',
							orderInfo: payRes.body, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
							success: function(res) {
								console.log('success:' + res);
								uni.navigateTo({
									url: "/pages/payment/success?orderid=" + payRes.order_id
								})
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
					})
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	.bill-content {
		.bill-header {
			width: 100%;
			background-color: #ffffff;
			padding: 30rpx 0 34rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-bottom: 10rpx;

			&-tips {
				font-size: 28rpx;
				color: $uni-text-color-opblack;
				line-height: 40rpx;
			}

			&-money {
				font-size: 60rpx;
				font-weight: bold;
				color: $uni-text-color-black;
				line-height: 86rpx;
				margin-top: 10rpx;
			}
		}

		.bill-line {
			background-color: #ffffff;
			width: calc(100% - 60rpx);
			padding: 0 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 100rpx;
			line-height: 100rpx;
			margin-bottom: 10rpx;

			&_param {
				font-size: 28rpx;
				color: $uni-text-color-black;
			}

			&_value {
				font-size: 28rpx;
				color: $uni-text-color-opblack;
			}
		}

		.bill-tips {
			font-size: 28rpx;
			color: $uni-text-color-opblack;
			line-height: 52rpx;
			background-color: #fff;
			width: calc(100% - 60rpx);
			padding: 22rpx 30rpx;

			text {
				color: $uni-text-color-black;
			}
		}

		.bill-methods {
			width: calc(100% - 60rpx);
			padding: 30rpx 30rpx 0 30rpx;
			background-color: #ffffff;
			margin-top: 10rpx;

			&_tips {
				color: $uni-text-color-opblack;
				font-size: 24rpx;
			}

			&_radio {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 2rpx solid #F5F5F5;
				padding: 20rpx 0;

				image {
					width: 212rpx;
					height: 64rpx;
				}
			}

			.padding {
				padding-bottom: 30rpx;

				image {
					width: 244rpx;
					height: 64rpx;
				}
			}
		}

		.button {
			width: 690rpx;
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			border-radius: 10rpx;
			margin: 50rpx auto 0;
			color: #ffffff;
			font-size: 32rpx;
			font-weight: bold;
			background: #FF6E00;
		}
	}
</style>